package Observer_pattern;

/**
 * Created with IntelliJ IDEA.
 * User: Bjarke
 * Date: 14-10-13
 * Time: 17:37
 * To change this template use File | Settings | File Templates.
 */
public class StockObserver implements Observer {
    private double ibmPrice;
    private double aaplPrice;
    private double googPrice;

    private static int observerIdTracker = 0;

    private int observerID;

    private Subject stockGrabber;

    public StockObserver(Subject stockGrabber){
        this.stockGrabber = stockGrabber;
        this.observerID = ++observerIdTracker;

        System.out.println("New Observer " + this.observerID);

        stockGrabber.register(this);

    }

    @Override
    public void update(double ibmPrice, double aaplPrice, double googPrice) {
        this.ibmPrice = ibmPrice;
        this.aaplPrice = aaplPrice;
        this.googPrice = googPrice;

        printThePrices();
    }

    public void printThePrices(){
        System.out.println("observer ID: " + observerID + "\nIBM: " + ibmPrice + "\nAAPL: " + aaplPrice
                + "\nGOOG: " + googPrice + "\n");
    }
}
